﻿import QtQuick 2.15
import QtQuick.Controls 2.15
/*
  伺服参数设置界面
*/

Item {
    id:backGround
    width: screenWidth
    height: 1600

    Rectangle{
        anchors.fill: backGround
        color: "#00BFFF"
        border.width: 5
        border.color: "#F0F8FF"
    }

    onVisibleChanged: {
        if(visible === true)
        {
            Cpp_Connect.pageNumber = 14
        }
    }

    Rectangle{
        anchors.horizontalCenter: backGround.horizontalCenter
        anchors.top: backGround.top
        width: backGround.width
        height: 810
        color: "#00BFFF"
        border.width: 5
        border.color: "#F0F8FF"

        Text{
            anchors.left: parent.left
            anchors.leftMargin: 30
            anchors.top: parent.top
            anchors.topMargin: 80
            font.pixelSize: 30
            font.bold: true
            text: qsTr("每圈脉冲数")
        }

        Rectangle{
            anchors.left: parent.left
            anchors.leftMargin: 230
            anchors.top: parent.top
            anchors.topMargin: 50
            width: 200
            height: 100
            radius: 20

            Text{
                id:mqmcs_Text
                anchors.centerIn: parent
                font.pixelSize:30
                font.bold: true
                visible: true
                text: Cpp_Connect.Per_Pulse_Count
            }

            TextInput{          // 每圈脉冲数 - 输入框
                id:mqmcs_Input
                anchors.centerIn: parent
                font.pixelSize: 30
                font.bold: true
                font.italic: true
                visible: false
                maximumLength: 10
                text: mqmcs_Text.text

                onEditingFinished: {
                    Cpp_Connect.write_modbus_rtu_Hold_F("200",mqmcs_Input.text)
                    mqmcs_Text.visible = true
                    mqmcs_Input.visible = false
                }
            }

            MouseArea{
                anchors.fill: parent

                onClicked: {
                    mqmcs_Input.forceActiveFocus()
                    mqmcs_Input.text = mqmcs_Text.text
                    mqmcs_Input.visible = true
                    mqmcs_Text.visible = false
                    mqmcs_Input.selectAll()
                }
            }
        }

        Text{
            anchors.left: parent.left
            anchors.leftMargin: 30
            anchors.top: parent.top
            anchors.topMargin: 240
            font.pixelSize: 30
            font.bold: true
            text: qsTr("每圈位移量")
        }

        Rectangle{
            anchors.left: parent.left
            anchors.leftMargin: 230
            anchors.top: parent.top
            anchors.topMargin: 210
            width: 200
            height: 100
            radius: 20

            Text{
                id:mqwyl_Text
                anchors.centerIn: parent
                font.pixelSize:30
                font.bold: true
                visible: true
                text: Cpp_Connect.Per_Move_Distance
            }

            TextInput{          // 每圈位移量 - 输入框
                id:mqwyl_Input
                anchors.centerIn: parent
                font.pixelSize: 30
                font.bold: true
                font.italic: true
                visible: false
                maximumLength: 10

                onEditingFinished: {
                    Cpp_Connect.write_modbus_rtu_Hold_F("202",mqwyl_Input.text)
                    mqwyl_Text.visible = true
                    mqwyl_Input.visible = false
                }
            }

            MouseArea{
                anchors.fill: parent

                onClicked: {
                    mqwyl_Input.forceActiveFocus()
                    mqwyl_Input.text = mqwyl_Text.text
                    mqwyl_Input.visible = true
                    mqwyl_Text.visible = false
                    mqwyl_Input.selectAll()
                }
            }
        }

        Text{
            anchors.left: parent.left
            anchors.leftMargin: 30
            anchors.top: parent.top
            anchors.topMargin: 390
            font.pixelSize: 30
            font.bold: true
            text: qsTr("最大切割长度")
        }

        Rectangle{
            anchors.left: parent.left
            anchors.leftMargin: 230
            anchors.top: parent.top
            anchors.topMargin: 360
            width: 200
            height: 100
            radius: 20

            Text{
                id:zdqgcd_Text
                anchors.centerIn: parent
                font.pixelSize:30
                font.bold: true
                visible: true
                text: Cpp_Connect.Max_Cut_Longth
            }

            TextInput{      // 最大切割长度 - 输入框
                id:zdqgcd_Input
                anchors.centerIn: parent
                font.pixelSize: 30
                font.bold: true
                font.italic: true
                visible: false
                maximumLength: 10

                onEditingFinished: {
                    Cpp_Connect.write_modbus_rtu_Hold_F("216",zdqgcd_Input.text)
                    zdqgcd_Text.visible = true
                    zdqgcd_Input.visible = false
                }
            }

            MouseArea{
                anchors.fill: parent

                onClicked: {
                    zdqgcd_Input.forceActiveFocus()
                    zdqgcd_Input.text = zdqgcd_Text.text
                    zdqgcd_Input.visible = true
                    zdqgcd_Text.visible = false
                    zdqgcd_Input.selectAll()
                }
            }
        }

        Text{
            anchors.left: parent.left
            anchors.leftMargin: 30
            anchors.top: parent.top
            anchors.topMargin: 540
            font.pixelSize: 30
            font.bold: true
            text: qsTr("反向软限位")
        }

        Rectangle{
            anchors.left: parent.left
            anchors.leftMargin: 230
            anchors.top: parent.top
            anchors.topMargin: 510
            width: 200
            height: 100
            radius: 20

            Text{
                id:fxrxw_Text
                anchors.centerIn: parent
                font.pixelSize:30
                font.bold: true
                visible: true
                text: Cpp_Connect.R_Limit
            }

            TextInput{          // 反向软限位 - 输入框
                id:fxrxw_Input
                anchors.centerIn: parent
                font.pixelSize: 30
                font.bold: true
                font.italic: true
                visible: false
                maximumLength: 10

                onEditingFinished: {
                    Cpp_Connect.write_modbus_rtu_Hold_F("218",fxrxw_Input.text)
                    fxrxw_Text.visible = true
                    fxrxw_Input.visible = false
                }
            }

            MouseArea{
                anchors.fill: parent

                onClicked: {
                    fxrxw_Input.forceActiveFocus()
                    fxrxw_Input.text = fxrxw_Text.text
                    fxrxw_Input.visible = true
                    fxrxw_Text.visible = false
                    fxrxw_Input.selectAll()
                }
            }
        }


        Text{
            anchors.left: parent.left
            anchors.leftMargin: 550
            anchors.top: parent.top
            anchors.topMargin: 80
            font.pixelSize: 30
            font.bold: true
            text: qsTr("找零点高速")
        }

        Rectangle{
            anchors.left: parent.left
            anchors.leftMargin: 750
            anchors.top: parent.top
            anchors.topMargin: 50
            width: 200
            height: 100
            radius: 20

            Text{
                id:zldgs_Text
                anchors.centerIn: parent
                font.pixelSize:30
                font.bold: true
                visible: true
                text: Cpp_Connect.F_Zero_HSpeed
            }

            TextInput{          // 找零点高速 - 输入框
                id:zldgs_Input
                anchors.centerIn: parent
                font.pixelSize: 30
                font.bold: true
                font.italic: true
                visible: false
                maximumLength: 10

                onEditingFinished: {
                    Cpp_Connect.write_modbus_rtu_Hold_F("220",zldgs_Input.text)
                    zldgs_Text.visible = true
                    zldgs_Input.visible = false
                }
            }

            MouseArea{
                anchors.fill: parent

                onClicked: {
                    zldgs_Input.forceActiveFocus()
                    zldgs_Input.text = zldgs_Text.text
                    zldgs_Input.visible = true
                    zldgs_Text.visible = false
                    zldgs_Input.selectAll()
                }
            }
        }

        Text{
            anchors.left: parent.left
            anchors.leftMargin: 550
            anchors.top: parent.top
            anchors.topMargin: 240
            font.pixelSize: 30
            font.bold: true
            text: qsTr("找零点低速")
        }

        Rectangle{
            anchors.left: parent.left
            anchors.leftMargin: 750
            anchors.top: parent.top
            anchors.topMargin: 210
            width: 200
            height: 100
            radius: 20

            Text{
                id:zldds_Text
                anchors.centerIn: parent
                font.pixelSize:30
                font.bold: true
                visible: true
                text: Cpp_Connect.F_Zero_LSpeed
            }

            TextInput{          // 找零点低速 - 输入框
                id:zldds_Input
                anchors.centerIn: parent
                font.pixelSize: 30
                font.bold: true
                font.italic: true
                visible: false
                maximumLength: 10

                onEditingFinished: {
                    Cpp_Connect.write_modbus_rtu_Hold_F("222",zldds_Input.text)
                    zldds_Text.visible = true
                    zldds_Input.visible = false
                }
            }

            MouseArea{
                anchors.fill: parent

                onClicked: {
                    zldds_Input.forceActiveFocus()
                    zldds_Input.text = zldds_Text.text
                    zldds_Input.visible = true
                    zldds_Text.visible = false
                    zldds_Input.selectAll()
                }
            }
        }

        Text{
            anchors.left: parent.left
            anchors.leftMargin: 550
            anchors.top: parent.top
            anchors.topMargin: 390
            font.pixelSize: 30
            font.bold: true
            text: qsTr("加减速时间")
        }

        Rectangle{
            anchors.left: parent.left
            anchors.leftMargin: 750
            anchors.top: parent.top
            anchors.topMargin: 360
            width: 200
            height: 100
            radius: 20

            Text{
                id:jjssj_Text
                anchors.centerIn: parent
                font.pixelSize:30
                font.bold: true
                visible: true
                text: Cpp_Connect.F_L_Speed_Time
            }

            TextInput{          // 加减速时间 - 输入框
                id:jjssj_Input
                anchors.centerIn: parent
                font.pixelSize: 30
                font.bold: true
                font.italic: true
                visible: false
                maximumLength: 10

                onEditingFinished: {
                    Cpp_Connect.write_modbus_rtu_Hold("208",(jjssj_Input.text))
                    jjssj_Text.visible = true
                    jjssj_Input.visible = false
                }
            }

            MouseArea{
                anchors.fill: parent

                onClicked: {
                    jjssj_Input.forceActiveFocus()
                    jjssj_Input.text = jjssj_Text.text
                    jjssj_Input.visible = true
                    jjssj_Text.visible = false
                    jjssj_Input.selectAll()
                }
            }
        }

        Text{
            anchors.left: parent.left
            anchors.leftMargin: 550
            anchors.top: parent.top
            anchors.topMargin: 540
            font.pixelSize: 30
            font.bold: true
            text: qsTr("刹车打开时间")
        }

        Rectangle{
            anchors.left: parent.left
            anchors.leftMargin: 750
            anchors.top: parent.top
            anchors.topMargin: 510
            width: 200
            height: 100
            radius: 20

            Text{
                id:scdksj_Text
                anchors.centerIn: parent
                font.pixelSize:30
                font.bold: true
                visible: true
                text: Cpp_Connect.Brake_Open_Time
            }

            TextInput{          // 刹车打开时间 - 输入框
                id:scdksj_Input
                anchors.centerIn: parent
                font.pixelSize: 30
                font.bold: true
                font.italic: true
                visible: false
                maximumLength: 10

                onEditingFinished: {
                    Cpp_Connect.write_modbus_rtu_Hold_F("1278",scdksj_Input.text)
                    scdksj_Text.visible = true
                    scdksj_Input.visible = false
                }
            }

            MouseArea{
                anchors.fill: parent

                onClicked: {
                    scdksj_Input.forceActiveFocus()
                    scdksj_Input.text = scdksj_Text.text
                    scdksj_Input.visible = true
                    scdksj_Text.visible = false
                    scdksj_Input.selectAll()
                }
            }
        }

        Text{
            anchors.left: parent.left
            anchors.leftMargin: 550
            anchors.top: parent.top
            anchors.topMargin: 690
            font.pixelSize: 30
            font.bold: true
            text: qsTr("刹车关闭延时")
        }

        Rectangle{
            anchors.left: parent.left
            anchors.leftMargin: 750
            anchors.top: parent.top
            anchors.topMargin: 660
            width: 200
            height: 100
            radius: 20

            Text{
                id:scgbys_Text
                anchors.centerIn: parent
                font.pixelSize:30
                font.bold: true
                visible: true
                text: Cpp_Connect.Brake_Close_Delay
            }

            TextInput{          // 刹车关闭延时 - 输入框
                id:scgbys_Input
                anchors.centerIn: parent
                font.pixelSize: 30
                font.bold: true
                font.italic: true
                visible: false
                maximumLength: 10

                onEditingFinished: {
                    Cpp_Connect.write_modbus_rtu_Hold("602",(scgbys_Input.text * 10).toString())
                    scgbys_Text.visible = true
                    scgbys_Input.visible = false
                }
            }

            MouseArea{
                anchors.fill: parent

                onClicked: {
                    scgbys_Input.forceActiveFocus()
                    scgbys_Input.text = scgbys_Text.text
                    scgbys_Input.visible = true
                    scgbys_Text.visible = false
                    scgbys_Input.selectAll()
                }
            }
        }

    }

    Rectangle{
        anchors.horizontalCenter: backGround.horizontalCenter
        anchors.top: backGround.top
        anchors.topMargin: 805
        width: backGround.width
        height: 150
        color: "#00BFFF"
        border.width: 5
        border.color: "#F0F8FF"

        Rectangle{
            anchors.left: parent.left
            anchors.leftMargin: 30
            anchors.verticalCenter: parent.verticalCenter
            width: 200
            height: 100
            radius: 20
            color: "#006cee"
            border.width: 1
            border.color: "#f0f8ff"

            Text{
                anchors.centerIn: parent
                font.pixelSize: 30
                font.bold: true
                text: qsTr("设置机械零点")
            }

            MouseArea{
                anchors.fill: parent

                onPressed: {
                  parent.color = "#ff3606"
                  Cpp_Connect.write_modbus_rtu_Coils("26","1")
                }

                onReleased: {
                  parent.color = "#006cee"
                  Cpp_Connect.write_modbus_rtu_Coils("26","0")
                }

                onPressAndHold: {
                    console.log("长按触发")
                    parent.color = "gold"
                  Cpp_Connect.write_modbus_rtu_Coils("147","1")
                }
            }

        }



        Text{
            anchors.verticalCenter: parent.verticalCenter
            anchors.left: parent.left
            anchors.leftMargin: 300
            font.pixelSize: 30
            font.bold: true
            text: qsTr("长按2s，坐标清零！")
        }


        Text{
            anchors.left: parent.left
            anchors.leftMargin: 650
            anchors.verticalCenter: parent.verticalCenter
            font.pixelSize: 30
            font.bold: true
            visible: false
            text: qsTr("编码器数据")
        }

        Rectangle{
            anchors.left: parent.left
            anchors.leftMargin: 850
            anchors.verticalCenter: parent.verticalCenter
            width: 200
            height: 100
            radius: 20
            color: "black"
            border.width: 1
            border.color: "#f0f8ff"
            visible: false

            Text{
                id: bmqsj_Text
                anchors.centerIn: parent
                font.pixelSize:30
                font.bold: true
                visible: true
                color: "aqua"
                text: Cpp_Connect.Encoder_Data
            }

        }

    }


    Rectangle{
        anchors.horizontalCenter: backGround.horizontalCenter
        anchors.top: backGround.top
        anchors.topMargin: 950
        width: backGround.width
        height: 150
        color: "#00BFFF"
        border.width: 5
        border.color: "#F0F8FF"

        Text{
            anchors.left: parent.left
            anchors.leftMargin: 650
            anchors.verticalCenter: parent.verticalCenter
            font.pixelSize: 30
            font.bold: true
            text: qsTr("当前位置")
        }

        Rectangle{
            anchors.left: parent.left
            anchors.leftMargin: 850
            anchors.verticalCenter: parent.verticalCenter
            width: 200
            height: 100
            radius: 20
            color: "black"
            border.width: 1
            border.color: "#f0f8ff"
            Text{
                id: currentLocaiton_Text
                anchors.centerIn: parent
                font.pixelSize:30
                font.bold: true
                color: "aqua"
                text: Cpp_Connect.currentLocation
            }

        }


        Rectangle{
            anchors.left: parent.left
            anchors.leftMargin: 30
            anchors.verticalCenter: parent.verticalCenter
            width: 200
            height: 100
            radius: 20
            color: "#006cee"
            border.width: 1
            border.color: "#f0f8ff"

            Text{
                anchors.centerIn: parent
                font.pixelSize: 30
                font.bold: true
                text: qsTr("读取电机位置")
            }

            MouseArea{
                anchors.fill: parent

                onPressed: {
                    parent.color = "#ff3606"
                }

                onReleased: {
                    parent.color = "#006cee"
                }
            }

        }


    }























    Rectangle{          // 返回按钮
        anchors.left: backGround.left
        anchors.leftMargin: 30
        anchors.bottom: backGround.bottom
        anchors.bottomMargin: 30
        radius: 10
        color: "#006cee"
        width: 200
        height: 100
        border.width: 1
        border.color: "#f0f8ff"

        Text{
            anchors.centerIn: parent
            font.pixelSize: 30
            font.bold: true
            text: qsTr("返  回")
        }

        MouseArea{
            anchors.fill: parent

            onPressed: {
                parent.color = "#ff3606"
            }

            onReleased: {
                parent.color = "#006cee"
                servoParameterSetting.visible = false
                advanceSettingWindow.visible = true
            }
        }
    }
}
